package com.ruoyi.project.channel.payerInfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.channel.payerInfo.domain.PayerInfo;
import com.ruoyi.project.channel.payerInfo.service.IPayerInfoService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 支付商扩展信息操作处理
 * 
 * @author CAIN
 * @date 2019-05-22
 */
@Controller
@RequestMapping("/channel/payerInfo")
public class PayerInfoController extends BaseController
{
    private String prefix = "channel/payerInfo";
	
	@Autowired
	private IPayerInfoService payerInfoService;
	
	@RequiresPermissions("channel:payerInfo:view")
	@GetMapping()
	public String payerInfo()
	{
	    return prefix + "/payerInfo";
	}
	
	/**
	 * 查询支付商扩展列表
	 */
	@RequiresPermissions("channel:payerInfo:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PayerInfo payerInfo)
	{
		startPage();
        List<PayerInfo> list = payerInfoService.selectPayerInfoList(payerInfo);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出支付商扩展列表
	 */
	@RequiresPermissions("channel:payerInfo:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PayerInfo payerInfo)
    {
    	List<PayerInfo> list = payerInfoService.selectPayerInfoList(payerInfo);
        ExcelUtil<PayerInfo> util = new ExcelUtil<PayerInfo>(PayerInfo.class);
        return util.exportExcel(list, "payerInfo");
    }
	
	/**
	 * 新增支付商扩展
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存支付商扩展
	 */
	@RequiresPermissions("channel:payerInfo:add")
	@Log(title = "支付商扩展", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PayerInfo payerInfo)
	{		
		return toAjax(payerInfoService.insertPayerInfo(payerInfo));
	}

	/**
	 * 修改支付商扩展
	 */
	@GetMapping("/edit/{payerId}")
	public String edit(@PathVariable("payerId") Long payerId, ModelMap mmap)
	{
		PayerInfo payerInfo = payerInfoService.selectPayerInfoById(payerId);
		if(payerInfo == null){
			payerInfo = new PayerInfo();
			payerInfo.setPayerId(payerId);
		}
		mmap.put("payerInfo", payerInfo);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存支付商扩展
	 */
	@RequiresPermissions("channel:payerInfo:edit")
	@Log(title = "支付商扩展", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PayerInfo payerInfo)
	{
		PayerInfo _payerInfo = payerInfoService.selectPayerInfoById(payerInfo.getPayerId());
		if(_payerInfo == null){
			toAjax(payerInfoService.insertPayerInfo(payerInfo));
		}
		return toAjax(payerInfoService.updatePayerInfo(payerInfo));
	}
	
	/**
	 * 删除支付商扩展
	 */
	@RequiresPermissions("channel:payerInfo:remove")
	@Log(title = "支付商扩展", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(payerInfoService.deletePayerInfoByIds(ids));
	}
	
}
